#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
using namespace std;

int n, x;
int lose[1010];
int win[1010];
int use[1010];

int dp[1010];

int main()
{
    cin >> n >> x;
    for (int i = 1; i <= n; i++)
    {
        cin >> lose[i] >> win[i] >> use[i];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = x; j >= use[i]; j--)
            dp[j] = max(dp[j] + lose[i], dp[j - use[i]] + win[i]);
        for (int j = use[i] - 1; j >= 0; j--)
            dp[j] += lose[i];
    }
    long long ans = 5 * (long long)dp[x];
    cout << ans << endl;
    system("pause");
    return 0;
}